<template>
  <div>
    <el-card style="width:50%">
      <el-form :model="user" label-width="80px" style="padding-right: 20px">
        <el-form-item label="原始密码" prop="username">
          <el-input v-model="user.password" placeholder="原始密码"></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="username">
          <el-input v-model="user.newPassword" placeholder="新密码"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="username">
          <el-input v-model="user.confirmPassword" placeholder="确认密码"></el-input>
        </el-form-item>
        <div style="text-align: center; margin: 20px">
          <el-button type="primary" @click="update">确认修改</el-button>
        </div>
      </el-form>
    </el-card>
  </div>

</template>

<script>
export default {
  name: "Person",
  data() {
    return {
      user: JSON.parse(localStorage.getItem('honey-user') || '{}'),
      rules: {
        password: [
          {
            required: true, message: '请输入原始密码', trigger: 'blur'
          },
        ]
      }
    }
  },
  methods: {
    update() {
      // 保存当前的用户信息到数据库
      this.$request.put('/user' ,this.user).then(res => {
        if (res.code === '200'){
          this.$message.success('保存成功')

          localStorage.setItem('honey-user',JSON.stringify(this.user))

          this.$emit('update:user',this.user)
        }
        else {
          this.$message.error(res.msg)
        }
      })
    }
  }
}

</script>
<style scoped>

</style>